import os
import sys

# 添加项目根目录到路径
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(current_dir)

from algorithms.enhanced_lstm_crf import create_and_train_enhanced_lstm_crf

def debug_enhanced_lstm_crf():
    """调试增强版LSTM-CRF模型"""
    print("🚀 开始调试排列5增强版LSTM-CRF模型")
    print("=" * 60)
    
    # 配置路径
    data_file = os.path.join(current_dir, 'scripts', 'plw', 'plw_history.csv')
    sequence_lstm_model_path = os.path.join(current_dir, 'scripts', 'plw', 'plw_sequence_lstm_model.pth')
    model_save_path = os.path.join(current_dir, 'scripts', 'plw', 'enhanced_lstm_crf_model.pth')
    
    print(f" 数据文件: {data_file}")
    print(f" 序列LSTM模型: {sequence_lstm_model_path}")
    print(f" 模型保存路径: {model_save_path}")
    
    # 检查必要的文件是否存在
    if not os.path.exists(data_file):
        print(f" 历史数据文件不存在: {data_file}")
        return False
    
    if not os.path.exists(sequence_lstm_model_path):
        print(f" 序列LSTM模型文件不存在: {sequence_lstm_model_path}")
        return False
    
    try:
        # 创建并训练增强版LSTM-CRF模型（使用较少的epochs进行测试）
        trainer = create_and_train_enhanced_lstm_crf(
            csv_file_path=data_file,
            sequence_lstm_model_path=sequence_lstm_model_path,
            model_save_path=model_save_path
        )
        
        if trainer is not None:
            print(" 排列5增强版LSTM-CRF模型创建成功！")
            return True
        else:
            print(" 排列5增强版LSTM-CRF模型创建失败！")
            return False
            
    except Exception as e:
        print(f" 创建过程出错: {e}")
        import traceback
        traceback.print_exc()
        return False

if __name__ == "__main__":
    debug_enhanced_lstm_crf()